package day07;
import java.util.Random;
import java.util.Scanner;
public class Exercise01 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
/*  1.猜数字小游戏
    训练目标: while(true)自造死循环
        int num = (int)(Math.random()*1000);
        System.out.println(num);
        while (true){
            System.out.println("猜吧！");
            int guess = sc.nextInt();
            if (guess>num){
                System.out.println("猜大了！");
            }else if(guess<num){
                System.out.println("猜小了！");
            }else{
                System.out.println("猜对了！");
                break;
            }
        }*/
    //2.需求:生成?位验证码(大写字母、小写字母、数字)
       /* String str = yanZhengMa(4);
        System.out.println("验证码为:"+str);*/

    //3.找到2到100之间的所有素数(质数)
/*        int num =0;
        for (int i = 2; i <=100 ; i++) {
            boolean flag = true;
            for (int j = 2; j <=i/2 ; j++) {
                if (i%j==0){
                    flag = false;
                    break;
                }
            }
            if(flag){
                System.out.print(i+"\t");
                num++;
            }
        }
        System.out.println();
        System.out.println("一共有"+num+"个素数");*/



        /*
        4.需求：
        机票价格按照淡季旺季、头等舱、商务舱和经济舱收费，
        输入机票原价、月份和头等舱、商务舱或经济舱，
        其中旺季（5-10月）头等舱9折，商务舱85折，经济舱8折，
        淡季（11月到来年4月）头等舱7折，商务舱65折，经济舱6折，
        最终输出机票价格

        System.out.println("请输入机票原价！");
        double price =sc.nextDouble();
        System.out.println("请输入月份");
        int month = sc.nextInt();
        System.out.println("请选择机舱: 1.头等舱 2.商务舱 3.经济舱");
        int a = sc.nextInt();
        double jipiao =jipiao(price,month,a);
        if (jipiao!=-1){
            System.out.println("最终价格为:"+jipiao);
        }

         */


/*      5.<<主持人大赛>>有6名评委给选手打分，要求分数范围为0到100之间的整数。
        选手的最后得分为：去掉最高分、最低分后的4个评委的平均分*/
        //获取分数
        double[] scores =fenshu();
        //计算总分
        double total =zongfen(scores);
        System.out.println("最终得分为"+total);
        //平均分
        double avg = pingjunfen(scores);
        System.out.println("平均分为"+avg);


    }
    public static String yanZhengMa(int len){
        String chs ="";
        char[] ch = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p',
                'q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G',
                'H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X',
                'Y','Z','1','2','3','4','5','6','7','8','9'};
        Random ran = new Random();
        for (int i = 0; i < len; i++) {
            int index = ran.nextInt(ch.length);
            chs += ch[index];
        }
        return chs;
    }

    public static double jipiao(double price,int month,int a){
        double jipiao = 0.0;
        if (month<1 || month>12){
            System.out.println("月份输入错误");
            return -1;
        }
        if (a<1 || a>3){
            System.out.println("无此舱型");
            return -1;
        }
        if (month>5 && month<10){
            switch (a){
                case 1:
                    jipiao=price*0.9;
                    break;
                case 2:
                    jipiao=price*0.85;
                    break;
                case 3:
                    jipiao=price*0.8;
                    break;
            }
        }else {
            switch (a){
                case 1:
                    jipiao=price*0.7;
                    break;
                case 2:
                    jipiao=price*0.65;
                    break;
                case 3:
                    jipiao=price*0.6;
                    break;
            }
        }
        return jipiao;
    }

    //获取分数
    public static double[] fenshu(){
        Scanner scan = new Scanner(System.in);
        double ch[] = new double[6];
        for (int i = 0; i < ch.length ; i++) {
            System.out.println("请输入第"+(i+1)+"位评委的分数");
            ch[i] = scan.nextDouble();
        }
        return ch;
    }
    //计算总分
    public static double zongfen(double[] scores){
        double total = 0.0;
        double max = scores[0];
        double min = scores[0];
        for (int i = 0; i <scores.length ; i++) {
            if (max<scores[i]){
                max = scores[i];
            }
            if (min>scores[i]){
                min = scores[i];
            }
        }
        for (int i = 0; i < scores.length; i++) {
            total+=scores[i];
        }
        return total-max-min;
    }
    //计算平均分
    public static double pingjunfen(double scores[]){
        double total =zongfen(scores);
        double avg = total/(scores.length-2);
        return  avg;
    }
}
